function trim(val)
{
	 return val.replace(/(^\s*)|(\s*$)/g, "");  
}

function checkSub(){
	
	if(trim(document.getElementById('consignee').value)==''){
		alert('收货人姓名不能为空');
		document.getElementById('consignee').focus();
		return false;
	}
	
	if(document.getElementById('level_no').value==''){
		alert('优先级不能为空');
		document.getElementById('level_no').focus();
		return false;
	}
	var email = document.addForm.email.value;
	  var chemEmails=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	
	  if(null == email || email == "")
	  {
	  	alert("邮箱不能为空!");
	  	document.getElementById("email").focus();
	  	return false;
	  }else if (!chemEmails.test(email)){
			alert("Email的格式不正确");
			document.getElementById("email").focus();
			return false;
	  }
	 var area_attr = document.getElementById('area_attr').value;
		if(document.getElementById('province').value != ''){
		var area_attr = '';
		area_attr += document.getElementById('province').value+'|';
		if(document.getElementById('eparchy_code').value!=''){
			area_attr += document.getElementById('eparchy_code').value+'|';
			if(document.getElementById('city_code').value!=''){
				area_attr += document.getElementById('city_code').value+'|';
			}
		 }
		}
		if(area_attr == ''){
			alert('请选择国家或地区！');
			return false;
		}
		document.getElementById('area_attr').value = area_attr;

	var post_code = document.getElementById('post_code').value;

	if(trim(post_code)!=''){
	   if(post_code.length != 6){
		  alert("邮编的格式不正确！");
		  document.getElementById('post_code').focus();
		  return false;
	   }
	}

	var tel = document.getElementById('tel').value;

	var chemTel = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	if(trim(tel)!=''){
		if(!chemTel.test(tel)){
			alert("电话格式输入不正确！");
			document.getElementById('post_code').focus();
			return false;
		}
	}
	
	if(trim(document.getElementById('cellphone').value)=='')
  {
      alert('请输入手机号码！');
	  document.getElementById('cellphone').focus();
      return false; 
  } else {
	var mobileReg =/^0{0,1}(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$/;
	if(!mobileReg.test(trim(document.getElementById('cellphone').value))){
      alert('请输入有效的手机号码！');
	  document.getElementById('cellphone').focus();
      return false;
	}
  }
	
	document.addForm.submit();
}

function searcherForm(){
	  //地区拼串
		var area_attr_str = "";
		if(document.getElementById("province").value!=""){
			area_attr_str += document.getElementById("province").value+"|";
			if(document.getElementById("eparchy_code").value!=""){
				area_attr_str += document.getElementById("eparchy_code").value+"|";
				if(document.getElementById("city_code").value!=""){
					area_attr_str += document.getElementById("city_code").value+"|";
				}
			}
		}
   	document.getElementById("req_area_attr").value = area_attr_str;
     document.indexForm.submit();
}

setProvince();


function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
		//DWRUtil.removeAllOptions('city_code');
		//DWRUtil.addOptions('city_code',{'':'请选择'});
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
     	DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}



function ChangeOrg(){
    document.getElementById("area_attr").value = '';
	document.getElementById("org1").style.display = "none";
	document.getElementById("org2").style.display = "inline";
	//document.getElementById("org_id").value = "";
}